package SpringBoot.spring_boot_starter_websocket.D01_获取服务器时间.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.titan.core.utils.common.domain.WebSocketClientMessage;
import com.titan.core.utils.common.domain.WebSocketServerMessage;

/**
 *
 *
 * @author 周成功
 *
 */
@RestController
@MessageMapping(value = "/WebSocketDemo/d01")
public class D01Controller {
    private SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
    @MessageMapping(value = "/getServerTime")
    @SendTo(value = "/WebSocketBroker/d01/getResponse")
    public WebSocketServerMessage serverTime(WebSocketClientMessage message) throws Exception {
        return new WebSocketServerMessage(message.getMessage() + sf.format(new Date()));
    }
}
